package com.ysd.modules.sys.controller;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ysd.common.utils.PageUtils;
import com.ysd.common.utils.R;
import com.ysd.modules.sys.entity.SysSchoolEntity;
import com.ysd.modules.sys.service.SysSchoolService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(description = "SYS-项目（院校）管理")
@RestController
@RequestMapping("/sys/sysSchool")
public class SysSchoolController {

	@Autowired
	private SysSchoolService schoolService;
	
	
	@PostMapping("addSchool")
	@ApiOperation("新增院校")
	public R addSchool(@RequestBody SysSchoolEntity s) {
		s.setCreateTime(new Date());
		int i = schoolService.addSchool(s);
		if(i>0) {
			return R.ok();
		}else {
			return R.error();
		}
	}
	
	@PostMapping("delSchool")
	@ApiOperation("根据id删除院校")
	public R delSchool(@RequestBody List<Integer> ids) {
		System.out.println(ids);
		boolean flag = schoolService.removeByIds(ids);
		if(flag) {
			return R.ok();
		}else {
			return R.error();
		}
	}
	
	@ApiOperation("修改院校信息")
	@PostMapping("updateSchool")
	public R updateSchool(@RequestBody SysSchoolEntity s) {
		System.out.println(s);
		int i = schoolService.updateSchool(s);
		if(i>0) {
			return R.ok();
		}else {
			return R.error();
		}
	}
	
	@ApiOperation("根据班级名分页查询班级")
	@GetMapping("getSchool")
	public R getSchool(String name, String address, Integer page, Integer limit) {
		PageUtils all = schoolService.getSchool(name, address, page, limit);
		return R.ok().put("data", all);
	}
	
	@ApiOperation("根据id查询院校信息")
	@GetMapping("select")
	public R selectSchool(Integer id) {
		SysSchoolEntity data = schoolService.getById(id);
		return R.ok().put("data", data);
	}
	
	@ApiOperation("查询所有学校")
	@GetMapping("getSchoolAll")
	public R getSchoolAll() {
		List<SysSchoolEntity> all = schoolService.list();
		return R.ok().put("data", all);
	}
	
}
